// pages/drivers/drivers.js

var publishRoute = require('../../utils/publishRoute.js');
var conf = require('../../JXDD_config.js')
const db = wx.cloud.database()

Page({
  /**
   * Page initial data
   */
  data: {
    isDriver:false,
    routes:null,
    dbid:"",
  },

  onGotUserInfo: function (e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.userInfo)
    console.log(e.detail.rawData)
  },
  formSubmit: function (event) {
    console.log(event.detail.formId)
    wx.navigateTo({
      url: '../chat/chat?id=' + event.detail.value.receiver_openid,
      success: function (res) {
        console.log(res)
      }, fail: function (res) {
        console.log(res)
      }
    })
  },
  routePlan:function(event){
    let plugin = requirePlugin('routePlan');
    let that = this;
    let key = conf.getQqMapKey();  //使用在腾讯位置服务申请的key
    let referer = '滴答';   //调用插件的app的名称
    let endPoint = JSON.stringify({  //终点
        'name': that.data.routes[0].startLocation.title,
        'latitude': that.data.routes[0].startLocation.location.lat,
        'longitude': that.data.routes[0].startLocation.location.lng
    });
    wx.navigateTo({
        url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
    });
  },
  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
    var isDriver=(options.isDriver == 'true' ? true : false);
    var dbid=options.dbid
    console.log("dbid 是:"+dbid)
    publishRoute.get_user_route(isDriver,db, this, {_id:dbid})
    this.setData({
      isDriver: isDriver,
      dbid:dbid
    })
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {

  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {

  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {

  },

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {

  },
  onPay: function () {
    wx.requestPayment(
      {
        'timeStamp': '',
        'nonceStr': '',
        'package': '',
        'signType': 'MD5',
        'paySign': '',
        'success': function (res) { console.log(res) },
        'fail': function (res) { console.log(res) },
        'complete': function (res) { console.log(res) }
      })
  },
  imageError: function (e) {
    console.log('image发生error事件，携带值为', e.detail.errMsg)
  }
})
